package com.juc.phaser.phaser9;

import java.util.concurrent.Phaser;

public class Run {
		/**
		 * 方法arrive()作用是使parties 加1 ，并且不在屏障处等待，直接向下面的代码继续运行
		 * 并且类Phaser有计数重置功能
		 */
	    /**
	     * arrive()方法是使getArrivedParties() 计数增一， 不等待其他线程到达屏障
	     * 多次getArrivedParties= 0 分析出结果：Phaser类经过屏障点后计数能被重置
	     * 
	     */
	
	  public static void main(String[] args) {
		     Phaser phaser = new Phaser(2) {
		    	 @Override
		    	protected boolean onAdvance(int phase, int registeredParties) {
		    		System.out.println(" 到达了 未通过！phase = " + phase + " registeredParties = " + registeredParties);
		    		return super.onAdvance(phase, registeredParties);
		    	};
		     };
		     System.out.println("A1 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     phaser.arrive();
		     System.out.println("A1 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     System.out.println("A2 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     phaser.arrive();
		     System.out.println("A2 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());

		     System.out.println("B1 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     phaser.arrive();
		     System.out.println("B1 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     System.out.println("B2 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     phaser.arrive();
		     System.out.println("B2 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
	  
		     
		     System.out.println("C1 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     phaser.arrive();
		     System.out.println("C1 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     System.out.println("C2 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
		     phaser.arrive();
		     System.out.println("C2 getPhase = " + phaser.getPhase() + " getRegisteredParties = " + phaser.getRegisteredParties() + " getArrivedParties = "+ phaser.getArrivedParties());
	  
	  }
	
}
